<template lang="html">
  <div class="bottombar">
    <div class="bottombar-box">
      <div class="bottombar-box-item"  v-for="(item,index) in dataList" :class="{'active':selectedIndex==index,'bottombar-box-left':index==0,'bottombar-box-right':index==(dataList.length-1)}" v-bind:style="{width:width+'%'}" @click="selectMenu(item,index)">{{item.text}}</div>
    </div>
  </div>
</template>

<script>
  import Constant from 'common/constant'

  export default {
    data () {
      return {
        selectedIndex: 0
      }
    },
    props: {
      dataList:{
        type:Array,
        default:[]
      },
      onSelected: {
        type: Function
      }
    },
    created:function(){
      var length = this.dataList.length?this.dataList.length:1;
      this.width = 80/length;
    },
    methods: {
      selectMenu(item,index) {
        if(this.selectedIndex != index){
          this.onSelected(item,index);
        }
        this.selectedIndex = index;
      },
      select(index){
        this.selectedIndex = index;
      }
    }
  }
</script>

<style lang="css">
  .bottombar {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #FFFFFF;
    border-top: 1px solid #E7E7E7;
    text-align: center;
    z-index: 2;
    height: 44px;
    line-height: 44px;
  }

  .bottombar-box {
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 7px 0;
  }
  .bottombar-box-item {
    height: 30px;
    line-height: 30px;
    color: #3FB9EE;
    padding: 0 30px;
    border-top: solid 1px #3FB9EE;
    border-bottom: solid 1px #3FB9EE;
    border-right: solid 1px #3FB9EE;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .bottombar-box-left {
    border-left: solid 1px #3FB9EE;
    border-bottom-left-radius:20px;
    border-top-left-radius:20px;
  }

  .bottombar-box-right {
    border-bottom-right-radius:20px;
    border-top-right-radius:20px;
  }

  .bottombar-box .active {
    background-color: #3FB9EE;
    color: #FFFFFF;
  }

</style>
